Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forkJoin): accept array of observable as parameter #714

Closed
wants to merge 1 commit into from

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Nov 12, 2015

relates to #594

This PR enables forkJoin accepts array of observable.

Creating overloads of function having array parameter to rest parameter requires some explicit unfolds due to behaviors of typescript (bit more explanation can be found here, way I used can be found in this PR as well.)

Performance wise, I haven't noticed big impact for general usecases of using rest parameters.
(numbers may vary). Checking typeof array for single observable, or array might impact bit more though.

before

     RxJS 4.0.6 |            RxJS 5.0.0-alpha.10 |          factor |      % improved
------------------------------------------------------------------------------------
38,677 (±4.83%) |               411,112 (±4.14%) |          10.63x |          962.9%

after

     RxJS 4.0.6 |            RxJS 5.0.0-alpha.10 |          factor |      % improved
------------------------------------------------------------------------------------
40,614 (±4.33%) |               406,452 (±4.23%) |          10.01x |          900.8%

const sources = this.sources;
let resultSelector: (...values: Array<any>) => any = null;
if (typeof sources[sources.length - 1] === 'function') {
resultSelector = sources.pop();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate for suggestion of mutating sources directly @Blesh , this seems way better than I did originally. I should've tried to look existing references before submitting PR.

// if the first and only other argument besides the resultSelector is an array
// assume it's been called with `forkJoin([obs1, obs2, obs3], resultSelector)`
if (sources.length === 1 && isArray(sources[0])) {
sources = <Array<Observable<any>>>sources[0];
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems previous comment went away by updating. Appreciate @Blesh for suggestion, it seems much better than I did first time. :)

@kwonoj
Copy link
Member Author

kwonoj commented Nov 13, 2015

Updating code lint-friendly makes one comment goes away :( I should buy mac.
Comment was

  • removed overload signature, after code update overloaded signature actually doesn't do much thing, simplified into single signature and let it does polymorphics

Updated perf shows quite similar to original code

      RxJS 4.0.6 |            RxJS 5.0.0-alpha.10 |          factor |      % improved
-------------------------------------------------------------------------------------
40,950 (±19.35%) |               437,477 (±4.65%) |          10.68x |          968.3%

@benlesh
Copy link
Member

benlesh commented Nov 18, 2015

Merged with 7f892ad after minor lint fix.

@benlesh benlesh closed this Nov 18, 2015
@kwonoj kwonoj deleted the feat-forkjoinarray branch November 18, 2015 21:45
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants